package com.legoo.studaychineseonline.activity;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.legoo.studaychineseonline.R;
import com.legoo.studaychineseonline.base.BaseActivity;
import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.DayViewDecorator;
import com.prolificinteractive.materialcalendarview.DayViewFacade;
import com.prolificinteractive.materialcalendarview.MaterialCalendarView;
import com.prolificinteractive.materialcalendarview.OnDateSelectedListener;
import com.prolificinteractive.materialcalendarview.format.ArrayWeekDayFormatter;
import com.prolificinteractive.materialcalendarview.format.MonthArrayTitleFormatter;

import org.threeten.bp.LocalDate;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ChoosClassTimeActivity extends BaseActivity implements OnDateSelectedListener {
    @BindView(R.id.tv_title_left)
    TextView tvTitleLeft;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_title_right)
    TextView tvTitleRight;
    @BindView(R.id.calendarView)
    MaterialCalendarView calendarView;

    @Override
    protected void myOnCreate(@Nullable Bundle savedInstanceState) {
        ButterKnife.bind(this);
        calendarView.addDecorator(new TodayDecorator());
        //英文月
        calendarView.setTitleFormatter(new MonthArrayTitleFormatter(getResources().getTextArray(R.array.custom_months)));
        //英文周
        calendarView.setWeekDayFormatter(new ArrayWeekDayFormatter(getResources().getTextArray(R.array.custom_weekdays)));
        //中午月
        calendarView.setTitleFormatter(null);
        //中午周
        calendarView.setWeekDayFormatter(null);

        calendarView.setOnDateChangedListener(this);
        final LocalDate calendar = LocalDate.now();
        calendarView.state().edit().setMinimumDate(calendar).commit();
        tvTitle.setText("选择试听时间");
        tvTitleLeft.setBackgroundResource(R.mipmap.img_fanhui);

    }

    @Override
    protected void initData() {
        LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) tvTitleRight.getLayoutParams();
        linearParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
        linearParams.width = LinearLayout.LayoutParams.WRAP_CONTENT;
        tvTitleRight.setLayoutParams(linearParams);
        tvTitleRight.setBackgroundResource(0);
        tvTitleRight.setGravity(Gravity.CENTER);
        tvTitleRight.setText("下一步");
    }

    @Override
    protected void resolveBundle(Bundle bundle) {

    }

    @Override
    protected int myLayoutId() {
        return R.layout.activity_choose_time;
    }

    @Override
    public void onDateSelected(@NonNull MaterialCalendarView widget, @NonNull CalendarDay date, boolean selected) {

    }


    private class TodayDecorator implements DayViewDecorator {

        private final CalendarDay today;
        private final Drawable backgroundDrawable;

        public TodayDecorator() {
            today = CalendarDay.today();
            backgroundDrawable = getResources().getDrawable(R.drawable.today_circle_background);
        }

        @Override
        public boolean shouldDecorate(CalendarDay day) {
            return today.equals(day);
        }

        @Override
        public void decorate(DayViewFacade view) {
            view.setBackgroundDrawable(backgroundDrawable);
        }
    }
}
